<?php
/**
 * Created by PhpStorm.
 * User: divya
 * Date: 2018/6/29
 * Time: 上午10:22
 */
$conn = mysqli_connect('localhost',"root","root") or die('connect faild'.mysqli_error());

// 防止中文乱码
//mysqli_query($conn,'SEL NAMES UTF8');
// 选择数据库
mysqli_select_db($conn,"ShowDB")or die('select faild'.mysqli_error());

// 执行sql语句
$sql = 'select * from t_type';
$result = mysqli_query($conn,$sql);

// 获取执行结果
$array = array();
$i = 0;
while ($row = mysqli_fetch_array($result)){
    $array[$i]['kindid'] = $row["type_id"];
    $array[$i]['kindname'] = $row['type_name'];
    $i++;
}
//var_dump($array);
// 关闭数据库
mysqli_close($conn);
// 返回json
$json = json_encode(array(
    'resultCode'=>200,
    "message"=>'success!',
    'data'=>$array
),JSON_UNESCAPED_UNICODE);
echo ($json);